<?php
include "./library.php";
$query = "select email from carpool.users where email = '".trim($_POST[id])."'";
$result = pg_query($query);
$checked_result = pg_fetch_array($result);

if($checked_result){
       echo "<script>alert('Your email is in use.')</script>";
       echo '<script>history.back()</script>';
}


$join_member = "insert into carpool.users (email, addr, nickname, pwd, pic) values ('".trim($_POST[id])."', '".trim($_POST[addr])."', '".trim($_POST[Nname])."', '".MD5(trim($_POST[pass]))."', '".trim($_POST[pic])."')";

$data = pg_query($join_member); 
if (!$data) { 
    echo "Problem with query " . $join_member . "<br/>"; 
    echo pg_last_error(); 
    exit(); 
} 

echo "<script>alert('Registration completed.')</script>";
echo '<script>window.location="./index.php"</script>';
?>